package phoenix.web.test_objects.data_providers;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseExt;

/**
 * Class contains test data for Index page
 */
public class RegistrationDataProviders extends TestBaseExt
{
	public RegistrationDataProviders(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	public Object[][] registrationDataMale()
	{
		// Generate email
		String emailTemplate = manager.config().MAIL_USER;
		String emailUniquePrefix = cronos().getCurrentDate("HHmmssyyMMdd") + randomizer().getRandomInt(1, 100).toString();
		String emailName = string().getSubstringBefore(emailTemplate, "@");
		String emailDomain = string().getSubstringAfter(emailTemplate, "@");

		String email = emailName + "+" + emailUniquePrefix + "@" + emailDomain;
		// Gender
		String gender = "male";
		// Password
		String password = "qweqweQ";
		// Birth date
		String birthDay = "12";
		String birthMonth = "11";
		String birthYear = "1990";

		testUser().setGender(gender)
				.setEmail(email)
				.setPassword(password)
				.setBirthDate(birthYear + "-" + birthMonth + "-" + birthDay);

		return new Object[][]
		{
				// Positive test
				{ gender, email, password, birthDay, birthMonth, birthYear }
		};
	}

	public Object[][] registrationDataFemale()
	{
		// Generate email
		String emailTemplate = manager.config().MAIL_USER;
		String emailUniquePrefix = cronos().getCurrentDate("HHmmssyyMMdd") + randomizer().getRandomInt(1, 100).toString();
		String emailName = string().getSubstringBefore(emailTemplate, "@");
		String emailDomain = string().getSubstringAfter(emailTemplate, "@");
		String email = emailName + "+" + emailUniquePrefix + "@" + emailDomain;
		// Gender
		String gender = "female";
		// Password
		String password = "qweqweQ";
		// Birth date
		String birthDay = "12";
		String birthMonth = "11";
		String birthYear = "1990";

		testUser().setGender(gender)
				.setEmail(email)
				.setPassword(password)
				.setBirthDate(birthYear + "-" + birthMonth + "-" + birthDay);

		return new Object[][]
		{
				// Positive test
				{ gender, email, password, birthDay, birthMonth, birthYear }
		};
	}

	public Object[][] validationDataBirth()
	{
		String currentDay = cronos().getCurrentDate("dd");
		String currentMonth = cronos().getCurrentDate("MM");
		String yearBirth18 = cronos().getDateFor18("yyyy");

		int day = Integer.parseInt(currentDay);
		String under18 = java.lang.String.valueOf(day + 1);
		String dayBirthUnder18 = under18;
		int value = Integer.parseInt(under18);

		if (value < 10)
		{
			dayBirthUnder18 = under18.replaceFirst("", "0");
		}

		return new Object[][]
		{
				// Positive test
				{ currentDay, currentMonth, yearBirth18, true },

				// Negative test
				{ "", "", "", false },
				{ currentDay, "", "", false },
				{ "", currentMonth, "", false },
				{ "", "", yearBirth18, false },
				{ dayBirthUnder18, currentMonth, yearBirth18, false }
		};
	}

	public Object[][] validationDataEmail()
	{
		String[] validList = { "+", ".", "_" };
		String[] invalidList = { "~", "`", "!", "@", "\"", "#", "�", "$", ";", "%", "^", ":", "&", "?", "*", "(", ")", "-", "<", ">", ",", "/", "|", "\\",
				"{",
				"}", "[", "]", "=", " " };

		String validChars = manager.randomizer().getRandomValueFromList(validList);
		String invalidChars = manager.randomizer().getRandomValueFromList(invalidList);

		String emailTemplate = manager.config().MAIL_USER;
		String emailUniquePrefix = cronos().getCurrentDate("HHmmssyyMMdd") + randomizer().getRandomInt(1, 100).toString();
		String emailName = string().getSubstringBefore(emailTemplate, "@");
		String emailDomain = string().getSubstringAfter(emailTemplate, "@");
		String email = emailName + validChars + emailUniquePrefix + "@" + emailDomain;

		return new Object[][]
		{
				// Positive test
				{ email, true },

				// Negative test
				{ "", false },
				{ "doren+unconfirmed@ag.net.ua", false },
				{ "doren+confirmed@ag.net.ua", false },
				{ "doren+remuved@ag.net.ua", false },
				{ "doren+" + invalidChars + "invalidchars@ag.net.ua", false },
				{ "doren+fakedomain@yopmail.com", false },
				{ "doren+1234567890qwertyuiopa1234567890qwertyuioa123456@yopmail.com", false }
		};
	}

	public Object[][] validationDataPassword()
	{
		String[] validList = { "!", "#", "$", "/", "\\", "*", "%", "@", "?", "-", "_" };
		String[] invalidList = { "~", "`", "\"", "�", ";", "^", ":", "&", "(", ")", "<", ">", ",", "|", "{", "}", "[", "]", "=", " " };

		String validChars = manager.randomizer().getRandomValueFromList(validList);
		String invalidChars = manager.randomizer().getRandomValueFromList(invalidList);

		return new Object[][]
		{
				// Positive test
				{ "valid" + validChars + "chars", true },

				// Negative test
				{ "123we", false },
				{ "G2kjsdhu883jjkasllaj7", false },
				{ "invalid" + invalidChars + "chars", false }
		};
	}

	public Object[][] validationDataLocation()
	{
		return new Object[][]
		{
				// Positive test
				{ "London, DA7 5SP", true },

				// Negative test
				{ "", false },
				{ "Ukraina, Zaporizhzhya", false }
		};
	}

	public Object[][] resendEmail()
	{
		String email = "doren+unconfirmed@ag.net.ua";
		String expectedText = "The activation email has been successfully resent to: " + email;

		return new Object[][]
		{
				{ email, expectedText },
		};
	}
}
